$(function() {
    var info = document.getElementById("info");
    $('.getCode').on('tap', function(e) {
        $.ajax({
            url: '/user/vCode',
            success: function(res) {
                mui.toast(`您的验证码是：${res.vCode}`);
            }
        })
        return false
    })

    $('.password').on('tap', 'img', function() {

        if ($('.passWordIpt').attr('type') == 'password') {
            $('.passWordIpt').attr('type', 'text')
            $(this).attr('src', './images/invisible.png')
        } else {
            $('.passWordIpt').attr('type', 'password')
            $(this).attr('src', './images/visible.png')
        }
    })
    $('.confirm').on('tap', 'img', function() {
        if ($('.confirmIpt').attr('type') == 'password') {
            $('.confirmIpt').attr('type', 'text')
            $(this).attr('src', './images/invisible.png')
        } else {
            $('.confirmIpt').attr('type', 'password')
            $(this).attr('src', './images/visible.png')
        }
    })



    $('.risBtn').on('tap', function(e) {

        var userNameIpt = $('.userNameIpt').val().trim()
        var phoneNumberIpt = $('.phoneNumberIpt').val().trim()
        var passWordIpt = $('.passWordIpt').val().trim()
        var confirmIpt = $('.confirmIpt').val().trim()
        var checkingIpt = $('.checkingIpt').val().trim()
        if (userNameIpt.length <= 0) {
            mui.toast('请输入用户名！');
        } else if (phoneNumberIpt.length <= 0) {
            mui.toast('请输入手机号码！');
        } else if (passWordIpt.length <= 0) {
            mui.toast('请输入密码！');
        } else if (confirmIpt.length <= 0) {
            mui.toast('请再次输入密码！');
        } else if (passWordIpt != confirmIpt) {
            mui.toast('两次输入密码不一致！');
        } else if (checkingIpt.length <= 0) {
            mui.toast('请输入验证码！');
        } else {
            $.ajax({
                url: '/user/register',
                type: 'post',
                data: {
                    username: userNameIpt,
                    password: passWordIpt,
                    mobile: phoneNumberIpt,
                    vCode: checkingIpt
                },
                success: function(res) {
                    console.log(res.success);
                    if (res.success == true) {
                        setTimeout(function() {
                            mui.toast(`注册成功`);
                        }, 500)
                        setTimeout(function() {
                            window.location.href = 'user.html'
                        }, 1000)
                    }
                },
                fail: function(err) {
                    mui.toast(err.message);
                }
            })
        }
        return false
    })
})